A Bytecode Alliance project
This crate contains bindings for WASI APIs for the worlds:
This crate is procedurally generated from WIT files using wit-bindgen
.
Usage
First you can depend on this crate via Cargo.toml
:
[]
= "0.12.0"
Next you can use the APIs in the root of the module like so:
This crate is intended to target components but today you need to go through
the intermediate build step of a core WebAssembly module using the wasm32-wasi
target:
$ cargo build --target wasm32-wasi
Next you'll want an "adapter" to convert the Rust standard library's usage of
wasi_snapshot_preview1
to the component model. An example adapter can be found
from Wasmtime's release page.
$ curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/v17.0.0/wasi_snapshot_preview1.command.wasm
Next to create a component you'll use the wasm-tools
CLI to create a
component:
$ cargo install wasm-tools
$ wasm-tools component new target/wasm32-wasi/debug/foo.wasm \
--adapt ./wasi_snapshot_preview1.command.wasm \
-o component.wasm
And finally the component can be run by a runtime that has Component Model support, such as Wasmtime:
$ wasmtime run component.wasm
Hello, world!
Development
The bulk of the wasi
crate is generated by the wit-bindgen
tool. The
src/bindings.rs
file can be regenerated with:
$ ./ci/regenerate.sh
WASI definitions are located in the wit
directory of this repository.
Currently they're copied from upstream repositories but are hoped to be better
managed in the future.
License
This project is triple licenced under the Apache 2/ Apache 2 with LLVM exceptions/ MIT licences. The reasoning for this is:
- Apache 2/ MIT is common in the rust ecosystem.
- Apache 2/ MIT is used in the rust standard library, and some of this code may be migrated there.
- Some of this code may be used in compiler output, and the Apache 2 with LLVM exceptions licence is useful for this.
For more details see
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache 2/ Apache 2 with LLVM exceptions/ MIT licenses, shall be licensed as above, without any additional terms or conditions.